/**
 * Copyright (c) 2018-present, Chen Guodong
 * All rights reserved.
 *
 * @flow
 */


<template>
  <div class="types-controller">
    <div class="title">项目概况</div>
    <ul class="items">
      <li @click="hanlderType(item.id)" :class="{item, active: selectedType === item.id}" v-for="(item, index) in types" :key="index">
        <span class="label">{{item.text}}</span>
        <span class="value">
          <i class="num" :id="'type-num-' + item.id">{{item.num}}</i>
          <b class="unit">个</b>
        </span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    getInfo: Function
  },
  data() {
    return {
      types: [
        { text: "全部", num: 44, id: "ALL" },
        { text: "计划中", num: 12, id: "IN_PLAN" },
        { text: "实施中", num: 20, id: "IN_PROGRESS" },
        { text: "已完成", num: 12, id: "COMPLETED" }
      ],
      selectedType: "ALL"
    };
  },
  methods: {
    hanlderType(data) {
      if (data == this.selectedType) {
        this.selectedType = 'ALL';
        this.getInfo();
      } else {
        this.selectedType = data;
        this.getInfo({ status: data });
      }
    }
  },
  mounted() {
    const options = {
      useEasing: false,
      useGrouping: false,
      separator: "",
      decimal: ""
    };
    this.types.map(item => {
      const i = new CountUp(
        "type-num-" + item.id,
        0,
        item.num,
        0,
        1.5,
        options
      );
      i.start();
    });
  },
  components: {}
};
</script>

<style lang='less' scoped>
@import "../utils/theme.less";
.types-controller {
  z-index: 2;
  height: 80px;
  font-size: 16px;
  display: flex;
  .title {
    height: 100%;
    font-size: 16px;
    display: inline-block;
    background: @primary;
    color: #fff;
    font-weight: bold;
    writing-mode: vertical-lr;
    text-align: center;
    padding: 5px;
    float: left;
    // margin-right: 10px;
  }
  .items {
    height: 100%;
    display: inline-block;
    float: left;
    padding: 5px 5px 0 5px;
    margin-left: 10px;
    cursor: pointer;
    .item {
      display: inline-block;
      margin-right: 10px;
      height: 100%;
      box-sizing: border-box;
      padding: 8px 12px;
      border: 1px solid @primary;
      background: rgba(255, 255, 255, 0.8);
      .label {
        display: block;
        font-size: 16px;
        width: 100%;
        text-align: left;
        line-height: 25px;
      }
      .value {
        display: block;
        height: 35px;
        line-height: 35px;
        .num {
          display: inline-block;
          font-size: 26px;
          font-weight: 500;
          padding: 0 5px;
          font-family: "digifacewide";
          color: red;
        }
      }
    }
    .active {
      border: 1px solid #fff;
      background: rgba(51, 133, 255, 0.8);
      .label,
      .value {
        color: #fff;
        .num {
          color: yellow;
        }
      }
    }
  }
}
</style>
